#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv
import sqlite3

class CreateDB:
  
      
    def __init__(self):
        '''
        Constructor
        ''' 


    def createTables(self):
        '''
                                       
       comments
        '''

        conn = sqlite3.connect('../Rebides.db')
        c = conn.cursor()
        
        c.execute('''create table if not exists teachers_information (teacher_code INTEGER, teacher_name TEXT, degree TEXT, course TEXT,
            category TEXT, regime TEXT, year INTEGER, establishment_type TEXT, establishment TEXT) ''')

        conn.commit()
        conn.close()
        pass


    def fillDataBase(self):

        conn = sqlite3.connect('../Rebides.db')
        c = conn.cursor()
        
        for x in range (0,11):
            f = open("../rebcsv/reb{0}.csv". format(x), "rb")
            reader = csv.reader(f)
            headers = reader.next()
            spamReader= csv.reader(f, delimiter=',')

            for row in spamReader:

                
                c.execute('''insert into teachers_information (teacher_code, teacher_name, degree, course, category, regime, year, establishment_type,
                        establishment) values("{0}","{1}","{2}","{3}","{4}","{4}","{6}","{7}","{8}")'''.\

                          format(str(row[0]),str(row[1]).replace('"', '\''),str(row[2]).replace('"', '\''),
                             str(row[3]).replace('"', '\''),str(row[4]).replace('"', '\''),
                             str(row[5]).replace('"', '\''),str(row[6]),str(row[7]).replace('"', '\''),
                             str(row[8]).replace('"', '\'')))
                
                pass
            pass
                
        f.close()
        pass
        conn.commit()
        conn.close()
    pass
#obj=CreateDB()
#obj.createTables()
#obj.fillDataBase()
